import { ref } from 'vue'
import type PageModal from '@/components/page-modal/PageModal.vue'
type CallbackFnType = (data?: any) => void

function usePageModal(newCallback?: CallbackFnType, editCallback?: CallbackFnType) {
  const modalRef = ref<InstanceType<typeof PageModal>>()

  function handleNewBtnClick() {
    modalRef.value?.setModalVisible()
    if (newCallback) {
      newCallback()
    }
  }

  function handleEditBtnClick(itemData: any) {
    // console.log(itemData)
    modalRef.value!.setModalVisible(false, itemData)
    if (editCallback) {
      editCallback(itemData)
    }
  }

  return { modalRef, handleNewBtnClick, handleEditBtnClick }
}

export default usePageModal
